﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Site.Master" AutoEventWireup="true" CodeBehind="UserManagement.aspx.cs" Inherits="BEELab.UserManagement" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server">
    <div id="wrap" class="clearfix">
        <div class="block">
            <h2 class="headline">User Management
            </h2>

            <asp:GridView ID="GridView1" runat="server" CssClass="dash-col" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" AllowPaging="True" AllowSorting="True">
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                    <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
                    <asp:BoundField DataField="University" HeaderText="University" SortExpression="University" />
                    <asp:ButtonField CommandName="ChangeAdmin" DataTextField="IsAdmin" DataTextFormatString="{0} (Change)" HeaderText="Admin" ShowHeader="True" Text="Admin" />
                    <asp:ButtonField CommandName="ChangePassword" Text="Change Password" />
                    <asp:ButtonField CommandName="Impersonate" Text="Login" />
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
                </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM [Users] WHERE [ID] = @original_ID AND [FirstName] = @original_FirstName AND [LastName] = @original_LastName AND [Email] = @original_Email AND [University] = @original_University AND [isAdmin] = @original_isAdmin AND [Salt] = @original_Salt AND [Hash] = @original_Hash" InsertCommand="INSERT INTO [Users] ([FirstName], [LastName], [Email], [University], [isAdmin], [Salt], [Hash]) VALUES (@FirstName, @LastName, @Email, @University, @isAdmin, @Salt, @Hash)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [Users]" UpdateCommand="UPDATE [Users] SET [FirstName] = @FirstName, [LastName] = @LastName, [Email] = @Email, [University] = @University, [isAdmin] = @isAdmin, [Salt] = @Salt, [Hash] = @Hash WHERE [ID] = @original_ID AND [FirstName] = @original_FirstName AND [LastName] = @original_LastName AND [Email] = @original_Email AND [University] = @original_University AND [isAdmin] = @original_isAdmin AND [Salt] = @original_Salt AND [Hash] = @original_Hash">
                <DeleteParameters>
                    <asp:Parameter Name="original_ID" Type="Int32" />
                    <asp:Parameter Name="original_FirstName" Type="String" />
                    <asp:Parameter Name="original_LastName" Type="String" />
                    <asp:Parameter Name="original_Email" Type="String" />
                    <asp:Parameter Name="original_University" Type="String" />
                    <asp:Parameter Name="original_isAdmin" Type="Boolean" />
                    <asp:Parameter Name="original_Salt" Type="String" />
                    <asp:Parameter Name="original_Hash" Type="String" />
                </DeleteParameters>
                <InsertParameters>
                    <asp:Parameter Name="FirstName" Type="String" />
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="Email" Type="String" />
                    <asp:Parameter Name="University" Type="String" />
                    <asp:Parameter Name="isAdmin" Type="Boolean" />
                    <asp:Parameter Name="Salt" Type="String" />
                    <asp:Parameter Name="Hash" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="FirstName" Type="String" />
                    <asp:Parameter Name="LastName" Type="String" />
                    <asp:Parameter Name="Email" Type="String" />
                    <asp:Parameter Name="University" Type="String" />
                    <asp:Parameter Name="isAdmin" Type="Boolean" />
                    <asp:Parameter Name="Salt" Type="String" />
                    <asp:Parameter Name="Hash" Type="String" />
                    <asp:Parameter Name="original_ID" Type="Int32" />
                    <asp:Parameter Name="original_FirstName" Type="String" />
                    <asp:Parameter Name="original_LastName" Type="String" />
                    <asp:Parameter Name="original_Email" Type="String" />
                    <asp:Parameter Name="original_University" Type="String" />
                    <asp:Parameter Name="original_isAdmin" Type="Boolean" />
                    <asp:Parameter Name="original_Salt" Type="String" />
                    <asp:Parameter Name="original_Hash" Type="String" />
                </UpdateParameters>
            </asp:SqlDataSource>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('a').filter(function (index) { return $(this).text() === "Delete"; }).click(function () { return confirm('Are you sure you want to delete this item?'); })
        });

    </script>
</asp:Content>
